import { Component } from 'vue-facing-decorator'
import Render from '@/render/Render'
import toNative from '@/utils/toNative'
import TableRender, { renderSlotButtons, type TableRenderColumnTypes } from '@/render/TableRender'
import type { VxeTableDataRow } from 'vxe-table'
import type { FilterDto } from '@/render/FilterRender'
import { DictionaryStatusCnEnum, getKeyToEnum, ProductTypeCnEnum } from '@/const/enum'
import type { AnyObject } from '@/types'
import { getDictionaryList } from '@/api/system'
import { Button } from 'ant-design-vue'

@Component
export class DictionaryView extends TableRender {

    pageTitle = '筛选'

    filterConfig() {
        return {
            dictName: {
                name: '字典名称',
                element: 'input',
            },
            dictType: {
                name: '字典类型',
                element: 'input',
            },
            status: {
                name: '状态',
                element: 'select',
                options: getKeyToEnum(DictionaryStatusCnEnum)
            },
            createTime: {
                name: '创建时间',
                element: 'dateTime',

            },
        } as FilterDto
    }

    tableColumnConfigOld = () => [
        {
            title: '序号',
            type: 'seq',
            width: 80
        },
        {
            field: 'dictName',
            title: '字典名称',
        },
        {
            field: 'dictType',
            title: '字典类型',
        },
        {
            field: 'status',
            title: '状态',
            params: {
                enum: DictionaryStatusCnEnum
            },
            slots: {
                default: 'enum',
            }
        },
        {
            field: 'remark',
            title: '备注',
        },
        {
            field: 'createTime',
            title: '创建时间',
        },
        {
            field: 'operate',
            title: '操作',
            width: 160,
            fixed: 'right',
            params: {
                buttons: renderSlotButtons(this)
            },
            slots: {
                default: 'buttons'
            }
        }
    ] as TableRenderColumnTypes<VxeTableDataRow>

    onToHistory() {
        this.$router.push({
            path: '/approval/audit-history'
        })
    }

    onLoadData(page: number, size: number, filters: AnyObject) {
        console.log(33333, filters)
        return getDictionaryList({
            pageNum: page,
            pageSize: size,
            ...filters
        })
    }

    renderTitleBtn() {
        return <Button type="link" onClick={this.onToHistory}>历史记录</Button>
    }

    render() {
        return <>
            {super.render()}
        </>
    }
}

export default toNative<{}, {}>(DictionaryView)